4
4
.
.
2
2
.
.
5
5
R
R
o
o
w
w
I
I
n
n
f
f
o
o
Row is Container View which organizes his child Views horizontally (next to each other).
Syntax
import androidx.compose.foundation.layout.Row
Row {
Text("First")
Text("Second")
}
E
E
x
x
a
a
m
m
p
p
l
l
e
e
In this example we create Row View with three Text Views next to each other.
Children are vertically aligned to: Top, Center, Bottom.
MainActivity.kt
package com.example.testcompose
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.ui.*
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.unit.dp
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Row(
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically //CenterVertically, Top, Bottom
) {
Text("Top" , Modifier.border(2.dp, Color.Red).padding(10.dp).align(Alignment.Top))
Text("Center", Modifier.border(2.dp, Color.Red).padding(10.dp)) //CenterVertically
Text("Bottom", Modifier.border(2.dp, Color.Red).padding(10.dp).align(Alignment.Bottom))
}
}
}
}
Output